package com.wsm.springBoot;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @name: SpringBootApplication
 * @Author: wangshimin
 * @Date: 2020/1/20  9:50
 * @Description:
 */
@Slf4j
@SpringBootApplication
public class SpringBootDemoApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext cac = SpringApplication.run(SpringBootDemoApplication.class, args);
        ConfigurableEnvironment environment = cac.getEnvironment();
        getMessage(environment);
    }

    private static void getMessage(Environment env) {
        String name = env.getProperty("spring.application.name");
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        String address = null;
        try {
            address = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            address = "127.0.0.1";
        }
        name = StringUtils.isEmpty(name) ? "" : name;
        port = StringUtils.isEmpty(port) ? "8080" : port;
        path = StringUtils.isEmpty(path) ? "" : path;

        log.info("\n" +
                        "》》》》》》》》》》》》》》》》》》》》》》\n" +
                        "{}启动成功\t\t\t\t\n" +
                        "登陆地址\t\t\t  http://{}\t\n" +
                        "swagger地址\t\t  http://{}\t\n" +
                        "》》》》》》》》》》》》》》》》》》》》》》\n"
                , name,
                address + ":" + port + path,
                address + ":" + port + path + "/swagger-ui.html");
    }
}
